<template>
  <div>
    <h1>欢迎光临神仙超市</h1>

    <table bordered="1">
      <tr>
        <td>食品</td>
        <td>单价</td>
        <td>发货地</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in shop">
        <td>{{i.name}}</td>
        <td>{{i.price}}</td>
        <td>{{i.send_area}}</td>
        <td>
          <button @click="buy(i.id)">购买</button>
        </td>
      </tr>
    </table>
    <router-link :to="{path:'/show_order'}">查看我的订单</router-link>
  </div>
</template>

<script>
export default {
  name: "show_shop",
  data() {
    return {
      shop:{},
      userid:localStorage.getItem('userid')
    }
  },
  methods:{
    get_shop(){
      this.$axios.get('users/shopM').then(res=>{
        this.shop = res.data.list
      })
    },
    buy(id){
      this.$axios.post('users/shopM',{'userid':this.userid,'shop_id':id}).then(res=>{
        if(res.data.code==200){
          alert('ok')
        }else {
          alert('no')
        }
      })
    }
  },
  mounted() {
    this.get_shop()
  }
}
</script>

<style scoped>

</style>
